/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.approval.dto.ApprovalGeneralSubmitDto;
import com.icinfo.cloud.provider.punish.approval.service.ICaseApprovalWaitRecordService;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.csource.manage.service.ICaseSourceDocumentRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.ShowEditButtonTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseDocumentModifyRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseDocumentRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseDocumentModifyRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseDocumentRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseDocumentModifyRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseDocumentRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseDocumentModifyRecordVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.DocumentRecordModifyReturnVo;
import com.icinfo.cloud.provider.punish.ucase.caseregister.dto.CaseRegisterSaveDto;
import com.icinfo.cloud.provider.punish.ucase.caseregister.service.ICaseRegisterService;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.tools.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 描述: 文书修改记录表 case_document_modify_record 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2023年01月06日
 */
@Slf4j
@Service
public class CaseDocumentModifyRecordServiceImpl extends MyBatisServiceSupport implements ICaseDocumentModifyRecordService {

    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private CaseDocumentModifyRecordMapper caseDocumentModifyRecordMapper;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Resource
    private ICaseRegisterService caseRegisterService;
    @Resource
    private ICaseApprovalWaitRecordService caseApprovalWaitRecordService;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Resource
    private ICaseSourceDocumentRecordService caseSourceDocumentRecordService;
    /**
     * 描述： 保存立案审批表文书修改记录
     *
     * @author: zhengqiang
     * @date: 2023/1/7
     * @param: caseDocumentModifyRecordSaveDto
     * @return {@link Result}
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result saveCaseDocumentModifyOfCaseRegister(CaseDocumentModifyOfCaseRegisterSaveDto caseDocumentModifyOfCaseRegisterSaveDto) {
        //修改立案信息
        CaseRegisterSaveDto caseRegisterSaveDto=new CaseRegisterSaveDto();
        BeanUtils.copyProperties(caseDocumentModifyOfCaseRegisterSaveDto,caseRegisterSaveDto);
        //校验保存参数
        String errorMsg =  caseRegisterService.checkAndDealCaseRegisterInfo(caseRegisterSaveDto);
        if (StringUtils.isNotEmpty(errorMsg)) {
            throw new BusinessException(errorMsg);
        }
        if(Constant.STRING_0.equals(caseDocumentModifyOfCaseRegisterSaveDto.getIsNeedApproval())) {
            //需要审批暂不更新表信息
           caseRegisterService.modifyCaseRegisterInfo(caseRegisterSaveDto);
        }
        HashMap<String, Object> dataMap=BaseUtil.javaToMap(caseRegisterSaveDto);
        //调用重新生成文书方法 生成完成后将documentId保存到documentIdAfterModify字段中
        DocumentRecordModifyDto modifyDto=new DocumentRecordModifyDto();
        BeanUtils.copyProperties(caseDocumentModifyOfCaseRegisterSaveDto,modifyDto);
        modifyDto.setDataMap(dataMap);
        DocumentRecordModifyReturnVo documentRecordModifyReturnVo = caseDocumentRecordService.modifyDocumentRecord(modifyDto);

        //保存文书修改记录
        caseDocumentModifyOfCaseRegisterSaveDto.setDocumentIdAfterModify(documentRecordModifyReturnVo.getDocumentIdAfterModify());
        caseDocumentModifyOfCaseRegisterSaveDto.setDocumentUrlBeforeModify(documentRecordModifyReturnVo.getDocumentUrlBeforeModify());
        caseDocumentModifyOfCaseRegisterSaveDto.setDocumentUrlAfterModify(documentRecordModifyReturnVo.getDocumentUrlAfterModify());
        CaseDocumentModifyRecordSaveDto saveDto = new CaseDocumentModifyRecordSaveDto();
        BeanUtils.copyProperties(caseDocumentModifyOfCaseRegisterSaveDto, saveDto);
        dealCaseDocumentModifyRecord(saveDto);
        //提交审批
        if(Constant.STRING_1.equals(caseDocumentModifyOfCaseRegisterSaveDto.getIsNeedApproval())) {
            ApprovalGeneralSubmitDto dto = caseDocumentModifyOfCaseRegisterSaveDto.getApprovalGeneralSubmitDto();
            dto.setIsEditApproval(Constant.STRING_1);
            dto.setDocId(documentRecordModifyReturnVo.getDocumentIdAfterModify());
            //caseApprovalWaitRecordService.documentGeneralSubmit(dto.getCaseId(), dto.getDocumentCatalogCode(), dto.getNextHandler(), dto.getOpinion(), dto.getPartyId(), dto.getCaseAssistId(), dto.getIsAutoApproval(), dto.getAutoTime(), dto.getDocId(), dto.getIsEditApproval());
            caseApprovalWaitRecordService.modifyDocumentGeneralSubmit(dto.getCaseId(), dto.getDocumentCatalogCode(), dto.getNextHandler(), dto.getOpinion(), dto.getPartyId(), dto.getCaseAssistId(), dto.getDocId(), dto.getIsEditApproval());
        }
        return Result.success(Constant.STRING_SUCCESS_EN);
    }

    /**
     * 描述： 保存文书修改记录
     *
     * @author: zhengqiang
     * @date: 2023/1/7
     * @param: caseDocumentModifyRecordSaveDto
     * @return {@link Result}
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result saveCaseDocumentModifyRecord(CaseDocumentModifyRecordSaveDto caseDocumentModifyRecordSaveDto) {
        //用重新生成文书方法 生成完成后将documentId保存到documentIdAfterModify字段中
        DocumentRecordModifyDto modifyDto=new DocumentRecordModifyDto();
        BeanUtils.copyProperties(caseDocumentModifyRecordSaveDto,modifyDto);
        DocumentRecordModifyReturnVo documentRecordModifyReturnVo = caseDocumentRecordService.modifyDocumentRecord(modifyDto);
        caseDocumentModifyRecordSaveDto.setDocumentIdAfterModify(documentRecordModifyReturnVo.getDocumentIdAfterModify());
        caseDocumentModifyRecordSaveDto.setDocumentUrlBeforeModify(documentRecordModifyReturnVo.getDocumentUrlBeforeModify());
        caseDocumentModifyRecordSaveDto.setDocumentUrlAfterModify(documentRecordModifyReturnVo.getDocumentUrlAfterModify());
        //保存文书修改记录
        dealCaseDocumentModifyRecord(caseDocumentModifyRecordSaveDto);
        //提交审批
        if(Constant.STRING_1.equals(caseDocumentModifyRecordSaveDto.getIsNeedApproval())) {
            ApprovalGeneralSubmitDto dto = caseDocumentModifyRecordSaveDto.getApprovalGeneralSubmitDto();
            dto.setIsEditApproval(Constant.STRING_1);
            dto.setDocId(documentRecordModifyReturnVo.getDocumentIdAfterModify());
            //caseApprovalWaitRecordService.documentGeneralSubmit(dto.getCaseId(), dto.getDocumentCatalogCode(), dto.getNextHandler(), dto.getOpinion(), dto.getPartyId(), dto.getCaseAssistId(), dto.getIsAutoApproval(), dto.getAutoTime(), dto.getDocId(), dto.getIsEditApproval());
            caseApprovalWaitRecordService.modifyDocumentGeneralSubmit(dto.getCaseId(), dto.getDocumentCatalogCode(), dto.getNextHandler(), dto.getOpinion(), dto.getPartyId(), dto.getCaseAssistId(), dto.getDocId(), dto.getIsEditApproval());
        }
        return Result.success(Constant.STRING_SUCCESS_EN);
    }

    /**
     * 【V1.11.2】描述： 案件来源登记表文书修改
     *
     * @author: zhengqiang
     * @date: 2023/3/17
     * @param: caseDocumentModifySaveDto
     * @return {@link Result}
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result saveCaseSourceDocumentModifyRecord(CaseDocumentModifyOfCaseSourceSaveDto caseDocumentModifySaveDto) {
        //调用重新生成文书方法 生成完成后将documentId保存到documentIdAfterModify字段中
        DocumentRecordModifyDto modifyDto = new DocumentRecordModifyDto();
        BeanUtils.copyProperties(caseDocumentModifySaveDto, modifyDto);
        modifyDto.setDataMap(caseDocumentModifySaveDto.getDataMap());
        DocumentRecordModifyReturnVo documentRecordModifyReturnVo = caseSourceDocumentRecordService.modifyCaseSourceDocumentRecord(modifyDto);

        //保存文书修改记录
        caseDocumentModifySaveDto.setDocumentIdAfterModify(documentRecordModifyReturnVo.getDocumentIdAfterModify());
        caseDocumentModifySaveDto.setDocumentUrlBeforeModify(documentRecordModifyReturnVo.getDocumentUrlBeforeModify());
        caseDocumentModifySaveDto.setDocumentUrlAfterModify(documentRecordModifyReturnVo.getDocumentUrlAfterModify());
        CaseDocumentModifyRecordSaveDto saveDto = new CaseDocumentModifyRecordSaveDto();
        BeanUtils.copyProperties(caseDocumentModifySaveDto, saveDto);
        dealCaseDocumentModifyRecord(saveDto);
        return Result.success(Constant.STRING_SUCCESS_EN);
    }

    /**
     * 文书修改记录处理
     *
     * @param caseDocumentModifyRecordSaveDto
     */
    private void dealCaseDocumentModifyRecord(CaseDocumentModifyRecordSaveDto caseDocumentModifyRecordSaveDto) {
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            throw new BusinessException("登录失效");
        }

        ConfigBusiParamDocumentInfo detailByDocumentCatalogCode = configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(caseDocumentModifyRecordSaveDto.getDocumentCatalogCode());
        if (!ShowEditButtonTypeEnum.ALLOW_EDIT.getCode().equals(detailByDocumentCatalogCode.getIsAllowEdit())
                && !ShowEditButtonTypeEnum.ALLOW_REMAKE.getCode().equals(detailByDocumentCatalogCode.getIsAllowEdit())) {
            throw new BusinessException(detailByDocumentCatalogCode.getDocumentCatalogName() + "【" + detailByDocumentCatalogCode.getDocumentCatalogCode() + "】不允许修改");
        }
        String modifyTitle = detailByDocumentCatalogCode.getDocumentCatalogName() + "修改申请";

        CaseDocumentModifyRecord caseDocumentModifyRecord = new CaseDocumentModifyRecord();
        BeanUtils.copyProperties(caseDocumentModifyRecordSaveDto, caseDocumentModifyRecord);
        //修改记录标题
        caseDocumentModifyRecord.setModifyTitle(modifyTitle);
        //修改内容
        String modifyColumnContent = JSON.toJSONString(caseDocumentModifyRecordSaveDto.getModifyColumnList());
        caseDocumentModifyRecord.setModifyColumnContent(modifyColumnContent);
        //设置原始文书id
        caseDocumentModifyRecord.setOriginalDocumentId(caseDocumentModifyRecordSaveDto.getDocumentId());
        //设置新生成的文书id
        caseDocumentModifyRecord.setDocumentId(caseDocumentModifyRecordSaveDto.getDocumentIdAfterModify());
        caseDocumentModifyRecord.setId(BaseUtil.createUid());
        caseDocumentModifyRecord.setCreateTime(new Date());
        caseDocumentModifyRecord.setCreateUserId(userInfo.getUserId().toString());
        caseDocumentModifyRecord.setCreateUserName(userInfo.getRealName());

        //设置修改标志id(同一个文书的修改记录标识id都相同)
        //查询原纪录是否存在修改记录
        Example example = new Example(CaseDocumentModifyRecord.class);
        example.createCriteria().andEqualTo("documentId", caseDocumentModifyRecordSaveDto.getDocumentId());
        List<CaseDocumentModifyRecord> list = caseDocumentModifyRecordMapper.selectByExample(example);
        if (ObjectUtil.isNotEmpty(list)) {
            CaseDocumentModifyRecord orgCaseDocumentModifyRecord = list.get(0);
            caseDocumentModifyRecord.setModifyFlagId(orgCaseDocumentModifyRecord.getModifyFlagId());
        } else {
            caseDocumentModifyRecord.setModifyFlagId(caseDocumentModifyRecordSaveDto.getDocumentId());
        }
        caseDocumentModifyRecordMapper.insertSelective(caseDocumentModifyRecord);
    }

    /**
     * 描述： 查看文书修改记录
     *
     * @author: zhengqiang
     * @date: 2023/1/7
     * @param: caseDocumentModifyRecordQueryDto
     * @return {@link List< CaseDocumentModifyRecordVo>}
     **/
    @Override
    public List<CaseDocumentModifyRecordVo> getCaseDocumentModifyRecordByCondition(CaseDocumentModifyRecordQueryDto queryDto) {
        List<CaseDocumentModifyRecordVo> caseDocumentModifyRecordVos = new ArrayList<>();
        if (ObjectUtils.isEmpty(queryDto.getDocumentCatalogCode())
                && ObjectUtils.isEmpty(queryDto.getDocumentId())) {
            throw new BusinessException("文书目录编码和文书id不能同时为空");
        }
        Example recordExample = new Example(CaseDocumentModifyRecord.class);
        Example.Criteria criteria = recordExample.createCriteria();
        criteria.andEqualTo("caseId", queryDto.getCaseId()).andEqualTo("isDelete", Constant.STRING_0);
        if (!ObjectUtils.isEmpty(queryDto.getDocumentId())) {
            criteria.andEqualTo("documentId", queryDto.getDocumentId());
        } else {
            criteria.andEqualTo("documentCatalogCode", queryDto.getDocumentCatalogCode());
        }

        if (!ObjectUtils.isEmpty(queryDto.getIsNeedApproval())) {
            criteria.andEqualTo("isNeedApproval", queryDto.getIsNeedApproval());
        }
        recordExample.orderBy("createTime").asc();

        List<CaseDocumentModifyRecord> caseDocumentModifyRecords = caseDocumentModifyRecordMapper.selectByExample(recordExample);
        caseDocumentModifyRecords.forEach(e -> {
            CaseDocumentModifyRecordVo recordVo = new CaseDocumentModifyRecordVo();
            BeanUtils.copyProperties(e, recordVo);
            List<CaseDocumentModifyColumnSaveDto> caseDocumentModifyColumnList = JSON.parseArray(e.getModifyColumnContent(), CaseDocumentModifyColumnSaveDto.class);
            recordVo.setModifyColumnList(caseDocumentModifyColumnList);
            if (YesOrNoEnum.YES.getCode().equals(e.getIsNeedApproval())) {
                recordVo.setIsNeedApprovalText("需要领导审批");
                if (Constant.STRING_1.equals(queryDto.getIsQueryNormal()) && ObjectUtils.isEmpty(e.getApprovalTime())) {
                    return;
                }
            } else {
                recordVo.setIsNeedApprovalText("不需要领导审批");
            }
            caseDocumentModifyRecordVos.add(recordVo);
        });

        return caseDocumentModifyRecordVos;
    }

    /**
     * 描述： 查看同一文书修改记录(正常完结流程)
     *
     * @author: zhengqiang
     * @date: 2023/3/6
     * @param: caseDocumentModifyRecordQueryDto
     * @return {@link List< CaseDocumentModifyRecordVo>}
     **/
    @Override
    public List<CaseDocumentModifyRecordVo> getNormalCaseDocumentModifyRecordList(CaseDocumentModifyRecordQueryDto queryDto) {
        List<CaseDocumentModifyRecordVo> caseDocumentModifyRecordVos = new ArrayList<>();
        if (ObjectUtils.isEmpty(queryDto.getDocumentCatalogCode())
                && ObjectUtils.isEmpty(queryDto.getDocumentId())) {
            throw new BusinessException("文书id不能同时为空");
        }
        List<CaseDocumentModifyRecord> caseDocumentModifyRecordList = getCaseDocumentModifyRecordListByDocumentId(queryDto.getDocumentId());
        if (ObjectUtils.isEmpty(caseDocumentModifyRecordList)) {
            return caseDocumentModifyRecordVos;
        }

        CaseDocumentModifyRecord caseDocumentModifyRecord = caseDocumentModifyRecordList.get(0);
        String modifyFlagId = caseDocumentModifyRecord.getModifyFlagId();
        List<CaseDocumentModifyRecord> recordList = null;
        if (ObjectUtils.isEmpty(modifyFlagId)) {
            recordList = getCaseDocumentModifyRecordByCatalogCode(queryDto);
        } else {
            queryDto.setModifyFlagId(modifyFlagId);
            recordList = getCaseDocumentModifyRecordListByModifyFlagId(queryDto);
        }

        recordList.forEach(e -> {
            CaseDocumentModifyRecordVo recordVo = new CaseDocumentModifyRecordVo();
            BeanUtils.copyProperties(e, recordVo);
            List<CaseDocumentModifyColumnSaveDto> caseDocumentModifyColumnList = JSON.parseArray(e.getModifyColumnContent(), CaseDocumentModifyColumnSaveDto.class);
            recordVo.setModifyColumnList(caseDocumentModifyColumnList);
            if (YesOrNoEnum.YES.getCode().equals(e.getIsNeedApproval())) {
                recordVo.setIsNeedApprovalText("需要领导审批");
                //排除审批中及审批退回数据
                if (Constant.STRING_1.equals(queryDto.getIsQueryNormal()) && ObjectUtils.isEmpty(e.getApprovalTime())) {
                    return;
                }
            } else {
                recordVo.setIsNeedApprovalText("不需要领导审批");
            }
            caseDocumentModifyRecordVos.add(recordVo);
        });

        return caseDocumentModifyRecordVos;
    }


    @Override
    public CaseDocumentModifyRecord getCaseDocumentModifyRecordByDocumentId(String documentId) {
        Example example=new Example(CaseDocumentModifyRecord.class);
        example.createCriteria().andEqualTo("documentId",documentId);
        List<CaseDocumentModifyRecord> list = caseDocumentModifyRecordMapper.selectByExample(example);
        if (ObjectUtils.isEmpty(list) && list.size() < 0){
            throw new BusinessException("文书修改记录不存在");
        }
        return list.get(0);
    }

    /**
     * 描述：通过文书id获取文书修改记录
     *
     * @param documentId 文档id
     * @return {@link CaseDocumentModifyRecord }
     * @author shishengyao
     * @date 2023/01/07
     */
    @Override
    public List<CaseDocumentModifyRecord> getCaseDocumentModifyRecordListByDocumentId(String documentId) {
        Example example=new Example(CaseDocumentModifyRecord.class);
        example.createCriteria().andEqualTo("documentId",documentId).andEqualTo("isDelete", Constant.STRING_0);
        List<CaseDocumentModifyRecord> list = caseDocumentModifyRecordMapper.selectByExample(example);
        return list;
    }

    /**
     * 根据文书id删除文书修改记录
     * @param documentId
     */
    @Override
    public void deleteCaseDocumentModifyRecordByDocumentId(String documentId) {
        Example example=new Example(CaseDocumentModifyRecord.class);
        example.createCriteria().andEqualTo("documentId",documentId);
        CaseDocumentModifyRecord caseDocumentModifyRecord = new CaseDocumentModifyRecord();
        caseDocumentModifyRecord.setIsDelete(Constant.STRING_1);
        caseDocumentModifyRecordMapper.updateByExampleSelective(caseDocumentModifyRecord, example);
    }

    /**
     * 描述： 根据原始文书id查询修改文书记录
     *
     * @author: zhengqiang
     * @date: 2023/3/2
     * @param: caseId
     * @param: modifyFlagId
     * @return {@link List< CaseDocumentModifyRecord>}
     **/
    @Override
    public List<CaseDocumentModifyRecord> getCaseDocumentModifyRecordListByOriginalDocumentId(String caseId, String originalDocumentId) {
        Example example=new Example(CaseDocumentModifyRecord.class);
        example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("originalDocumentId", originalDocumentId).andEqualTo("isDelete", Constant.STRING_0);
        List<CaseDocumentModifyRecord> list = caseDocumentModifyRecordMapper.selectByExample(example);
        return list;
    }

    /**
     * 描述： 根据修改标识id查询修改文书记录
     *
     * @author: zhengqiang
     * @date: 2023/3/2
     * @param: queryDto
     * @return {@link List< CaseDocumentModifyRecord>}
     **/
    @Override
    public List<CaseDocumentModifyRecord> getCaseDocumentModifyRecordListByModifyFlagId(CaseDocumentModifyRecordQueryDto queryDto) {
        if (ObjectUtils.isEmpty(queryDto.getCaseId())) {
            throw new BusinessException("案件id不允许为空");
        }
        if (ObjectUtils.isEmpty(queryDto.getModifyFlagId())) {
            throw new BusinessException("修改标识id不允许为空");
        }

        Example example = new Example(CaseDocumentModifyRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("caseId", queryDto.getCaseId()).andEqualTo("modifyFlagId", queryDto.getModifyFlagId())
                .andEqualTo("isDelete", Constant.STRING_0);
        if (ObjectUtil.isNotEmpty(queryDto.getIsNeedApproval())) {
            criteria.andEqualTo("isNeedApproval", queryDto.getIsNeedApproval());
        }
        example.orderBy("createTime").asc();
        List<CaseDocumentModifyRecord> list = caseDocumentModifyRecordMapper.selectByExample(example);
        return list;
    }

    /**
     * 描述： 根据文书目录编码查询修改文书记录
     *
     * @author: zhengqiang
     * @date: 2023/3/6
     * @param: queryDto
     * @return {@link List< CaseDocumentModifyRecord>}
     **/
    @Override
    public List<CaseDocumentModifyRecord> getCaseDocumentModifyRecordByCatalogCode(CaseDocumentModifyRecordQueryDto queryDto) {
        if (ObjectUtils.isEmpty(queryDto.getCaseId())) {
            throw new BusinessException("案件id不允许为空");
        }
        if (ObjectUtils.isEmpty(queryDto.getDocumentCatalogCode())) {
            throw new BusinessException("文书目录编码不能为空");
        }
        Example recordExample = new Example(CaseDocumentModifyRecord.class);
        Example.Criteria criteria = recordExample.createCriteria();
        criteria.andEqualTo("caseId", queryDto.getCaseId()).andEqualTo("isDelete", Constant.STRING_0);
        criteria.andEqualTo("documentCatalogCode", queryDto.getDocumentCatalogCode());
        if (!ObjectUtils.isEmpty(queryDto.getIsNeedApproval())) {
            criteria.andEqualTo("isNeedApproval", queryDto.getIsNeedApproval());
        }
        recordExample.orderBy("createTime").asc();
        List<CaseDocumentModifyRecord> caseDocumentModifyRecords = caseDocumentModifyRecordMapper.selectByExample(recordExample);
        return caseDocumentModifyRecords;
    }
}
